//
// Created by Apple on 2021/11/28.
//

#ifndef EXERCIS_CPP_RTSPTEST_H
#define EXERCIS_CPP_RTSPTEST_H

#include <regex>
#include <string>

bool IsValidRtspUrlWithoutUser(const std::string rtspUrl)
{
    std::regex regExpress1("^rtsp://\\d{1,3}.\\d{1,3}.\\d{1,3}.\\d{1,3}:\\d{1,5}/[^\\s]+");
    std::regex regExpress2("^rtsp://\\d{1,3}.\\d{1,3}.\\d{1,3}.\\d{1,3}/[^\\s]+");
    return std::regex_search(rtspUrl, regExpress1) || std::regex_search(rtspUrl, regExpress2);
}

bool IsValidRtspUrlWithUser(const std::string rtspUrl)
{
    std::regex regExpress1("^rtsp://\\w:\\w{1,20}@\\d{1,3}.\\d{1,3}.\\d{1,3}.\\d{1,3}:\\d{1,5}/[^\\s]+");
    std::regex regExpress2("^rtsp://\\w{1,20}:\\w{1,20}@\\d{1,3}.\\d{1,3}.\\d{1,3}.\\d{1,3}:/[^\\s]+");
    return std::regex_search(rtspUrl, regExpress1) || std::regex_search(rtspUrl, regExpress2);
}

bool ISValiedRtspUrl(const std::string rtspUrl)
{
    return IsValidRtspUrlWithoutUser(rtspUrl) || IsValidRtspUrlWithUser(rtspUrl);
}


#endif //EXERCIS_CPP_RTSPTEST_H
